<template>
  <el-card class="wrap">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="80px" class="demo-ruleForm">
      <el-form-item label="名称" prop="name">
        <el-input v-model="ruleForm.name" />
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input-number v-model="ruleForm.sort" controls-position="right" step-strictly :min="1" :max="10">
        </el-input-number>
      </el-form-item>
      <el-form-item label="状态" prop="sort">
        <el-radio-group v-model="ruleForm.status">
          <el-radio :label="1">显示</el-radio>
          <el-radio :label="0">隐藏</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
export default {
  name: 'CategoryCreate',
  data() {
    return {
      ruleForm: {
        name: '',
        sort: 1,
        status: 1,
      },
      rules: {
        name: [{ required: true, message: '请输入分类名称', trigger: 'blur' }],
        sort: [{ required: true, message: '请输入分类排序', trigger: 'blur' }],
      },
    }
  },
  mounted() { },
  methods: {
    // 提交表单
    submitForm(formName) {
      this.createTag()
    },
    // 创建分类
    createTag() {
      const data = {
        name: this.ruleForm.name,
        sort: this.ruleForm.sort, // 排序
        status: 1, // 是否显示
      }
      this.$api.httpTagCreate(data).then((res) => {
        if (res.code === 200) {
          this.$message.success('添加成功')
          this.$router.push('/tag/list')
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    // 重置表单
    resetForm(formName) {
      // this.$refs[formName].resetFields()
    },
  },
}
</script>

<style scoped lang="scss">
</style>
